#!/usr/bin/env python
import logging
import wsgiref.handlers
from google.appengine.ext import webapp
from google.appengine.ext import db
from google.appengine.ext.webapp import template
from dbmodel import Competition
from dbmodel import Class
from dbmodel import TimeFunctions
from renderer import PlainRenderer
import os
import urllib
from google.appengine.api import quota
from google.appengine.api import memcache


class MainHandler(webapp.RequestHandler):

  def get(self, key = None):

    if self.request.get('class') != None and key is not None:
	#Check for cached rendered content in memory
	data = memcache.get('results_'+key+'_'+self.request.get('class'))
#	if data is not None:
		#self.response.out.write(data)
		#return
		
    renderer = PlainRenderer()
    data = renderer.renderResultList(key,self.request.get('class'))
    self.response.out.write(data)


def main():
  logging.getLogger().setLevel(logging.DEBUG)
  application = webapp.WSGIApplication([(r'/View/(.+)', MainHandler)],
                                       debug=True)
  wsgiref.handlers.CGIHandler().run(application)


if __name__ == '__main__':
  main()
